4.0 Data Representation - Integers
Tags: #◇Computer Science #◇CCICOMP #◇Problem Solving #◇M2
◇Overview
Data representation involves encoding information into binary form so it can be reliably transported and processed by computer circuitry. Any numeric representation format balances size, range, accuracy, ease of manipulation, and standardization. Integers can be represented as unsigned (only non-negative values) or signed (capable of representing both positive and negative values). While various encoding schemes exist for signed integers, modern CPUs almost universally use the 2's complement scheme. Since data types use fixed-width bit strings, calculations that exceed the format's capacity result in overflow, producing mathematically illogical values.
◇Important Formulas
Unsigned Integers Value Evaluation: An -bit unsigned integer has the decimal value:
Range: to . For example, an -bit unsigned integer ranges from to . Zero Extension: To expand the width of an unsigned integer, simply pad the left side (most significant bits) with s.
Signed Integers
Signed integers allocate the Most Significant Bit (MSB) as the sign bit: for positive, for negative. Sign-and-Magnitude: The MSB is the sign, and the remaining bits represent the absolute magnitude of the number in standard binary. 1's Complement: To represent a negative number, start with the positive unsigned binary value and invert every bit (, ). 2's Complement: To represent a negative number, invert every bit of the positive unsigned binary value and add .
Range: to . E.g., for -bit: to .
Only uses one representation of (unlike 1's complement and sign-and-magnitude). Sign Extension: To expand the width of a signed integer, replicate the sign bit to the left (e.g., for negatives, for positives).
◇Worked Examples
1. Converting to 2's Complement
Represent as an -bit signed integer in 2's complement.
- Determine absolute value in binary: (with leading zeros to make bits).
- Invert bits (1's complement): .
- Add : .
Result: .
2. Converting from 2's Complement
Find the decimal equivalent of the -bit 2's complement number .
- Check MSB: means negative.
- Invert bits: .
- Add : .
- Convert to decimal: .
- Apply sign: .
3. Overflow Condition
Add the -bit signed values and . Addition:
Notice the MSB is now . In an -bit signed 2's complement system, is interpreted as . Because , which exceeds the maximum -bit positive range of , the magnitude overflowed into the sign bit, causing an illogical negative result.
◇References & Navigation
- Previous Topic: ◇Introduction to Number Systems
- Next Topic: ◇Data Representation - Real Numbers
- Related Notes: ◇Integer Representation & Fixed-Point Arithmetic, ◇Data Representation - Characters and Boolean
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
Which of the following best describes data representation in the context of computer circuitry?
What distinguishes unsigned integers from signed integers?
Which encoding scheme is almost universally used by modern CPUs for signed integers?
What happens when a calculation exceeds the fixed-width capacity of an integer format?
How is zero extension performed on an unsigned integer?
In a signed integer representation, what does a Most Significant Bit (MSB) of 1 indicate?
How do you convert a positive binary number to its 1's complement negative equivalent?
What is the formula for the maximum range of an n-bit unsigned integer?
What is a key advantage of 2's complement over sign-and-magnitude representation?
How is sign extension performed on a negative 2's complement signed integer?